//
//  DnImageCropperViewController.m
//  DnImageCropper
//
//  Created by Ngoc on 08/11/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DnImageCropperViewController.h"

@implementation DnImageCropperViewController

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad
 {
     
     NSString *imageName = @"oldeditwindow.jpg";
     
     dnSuperImageView = [[ DnSuperImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 320) image:[UIImage imageNamed:imageName]];
     [self.view addSubview:dnSuperImageView];    
 [super viewDidLoad];
 }

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction) ShowImageCropper:(id) sender
{
    UIButton *button = (UIButton*) sender;
    switch (button.tag) {
        case 1:
            _userResizeMethod = S3X4;
            break;
        case 2:
            _userResizeMethod = S4X3;
            break;
        case 3:
            _userResizeMethod = S1X1;
            break;
        default:
            _userResizeMethod = FreeDom;
            break;
    }
    [dnSuperImageView setResizeStrategy:_userResizeMethod];
    [dnSuperImageView startAction:ActionCrop];
    
}
-(IBAction) filter
{
    [dnSuperImageView applyEffect:Brightness];
    _isApplyEffect   =YES;
}
-(void) startActionStraighten:(id)sender
{
    [dnSuperImageView startAction:ActionStraighten];
}
-(IBAction) selectedRegionDone:(id)sender
{
    [dnSuperImageView finishCurrentAction];
    
}
-(IBAction) hiddenImageCropper:(id)sender
{
    if (_isApplyEffect) {
        [dnSuperImageView cancelApplyCurrentEffect];
        _isApplyEffect = NO;
    }
    else
    [dnSuperImageView  cancelCurrentAction];
}
-(IBAction) verticalFlip:(id)sender
{
    [dnSuperImageView flipImage:FlipVertical];
}
-(IBAction) horizontalFlip:(id)sender
{
    [dnSuperImageView flipImage:FlipHorizontal];
}
-(IBAction) leftFlip:(id)sender
{
    [dnSuperImageView flipImage:FlipLeft];
}
-(IBAction) rightFlip:(id)sender
{
    [dnSuperImageView flipImage:FlipRight];
}
@end
